<template>
	<gui-page ref="guiPage" :customHeader="true">
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :leftType="'1'" :title="$t('hardware.pageTitleEnter')" :rightText="$t('distributedEnter.scanRecord')"
				@clickRight="clickRight" @clickLeftBack="clickLeftBack"></nav-bar-custom>
		</template>
		<template v-slot:gBody>
			<scroll-view scroll-y  class="page-auto paddingbottom">
				<!-- 页面头部入库单信息 -->
				<view class="card-mini">
					<view class="card-mini-head">
						<view class="title-line"></view>
						{{$t('purchaseReturn.materialReceiptInfo')}}
					</view>
					<!-- <view v-if="data.stockDetail" class="card-mini-body">
						<view class="card-mini-item">
							<view class="mini-item-50">
								<text class="mini-item-title">收料通知单号：</text>{{ data.stockDetail.receiptCode }}
							</view>
							<view class="mini-item-50">
								<text class="mini-item-title">日期：</text>{{ data.stockDetail.receiptDate }}
							</view>
						</view>
					</view> -->
				    <view v-if="data.stockDetail" class="card-mini-body">
					    <view class="card-mini-item">
							<view class="mini-item-50 maxWidth">
								<text class="mini-item-title">{{$t('stockManage.singleReceiving')}}：</text>{{ data.stockDetail.receiptCode }}
							</view>
						</view>
						<view class="card-mini-item">
							<text class="mini-item-title">{{$t('stockManage.receivingOrderQty')}}：{{ data.stockDetail.sumQty }}</text>
						</view>
						<view class="card-mini-item">
							<view class="mini-item-50 maxWidth">
								<text class="mini-item-title">{{$t('translationImage.documentationDate')}}：{{ data.stockDetail.receiptDate }}</text>
							</view>
						</view>
						<view class="card-mini-item">
							<view class="mini-item-50">
								<text class="mini-item-title automini">{{$t('stockManage.stayPointQty')}}：{{ Number(data.stockDetail.unPointNum) }}</text>
							</view>
							<view class="mini-item-50">
								<text class="mini-item-title automini">{{$t('stockManage.storageQty')}}：</text>{{ data.stockDetail.sumInstockQty }}
							</view>
						</view>
						<!-- <view class="card-mini-item">
							<view class="mini-item-50">
								<text class="mini-item-title">{{$t('stockManage.giveQty')}}：</text>{{ data.stockDetail.giftNum }}
							</view>
						</view> -->
						<view class="card-mini-item">
							<view class="mini-item-50 maxWidth">
								<text class="mini-item-title">{{$t('distributedEnter.scannedQuantity')}}：</text> {{ data.stockDetail.currentScanSumNum}}
							</view>
						</view>
					</view>
				</view>
				<!-- 表单填写区域 -->
				<view class="custom-form-card">
					<view class="custom-card-title">
						<text class="title-line"></text>
						{{$t('hardware.warehousingInput')}}
					</view>
					<view class="custom-card-itemTwo" style="padding: 20rpx 0;">
						<uni-easyinput class="uni-mt-5" suffixIcon="scan" :placeholder="$t('hardwareOut.pleaseScanMaterial')" v-model="data.scanValue"
							@confirm="confirm" @iconClick="iconClick">
						</uni-easyinput>
					</view>
					<view class="custom-card-itemTwo" style="padding: 5rpx 0;">
						<text class="item-info-title"><text class="required-color">*</text>{{$t('stockManage.purposeWarehouse')}}：</text>
						<input type="text" 
						disabled
						style="margin: 8rpx 0;text-align: right;"
						class="gui-form-input" 
						v-model="data.warehouseCode" 
						:placeholder="$t('pageTranslation.bringFromMaterialCard')" />
						<!-- <superwei-combox style="text-align: right;" :candidates="data.transferIntoList" placeholder="请选择或输入"
							:isJSON="true" keyName="warehouseName" v-model="data.selectedOut"></superwei-combox> -->
					</view>
					<view class="custom-card-itemTwo noborder" style="padding: 5rpx 0;">
						<text class="item-info-title"><text class="required-color">*</text>{{$t('stockManage.purposeSeat')}}：</text>
							<input type="text" 
							disabled
							style="margin: 8rpx 0;text-align: right;"
							class="gui-form-input" 
							v-model="data.locationCode" 
							:placeholder="$t('pageTranslation.bringFromMaterialCard')" />
						<!-- <superwei-combox style="text-align: right;" :candidates="data.warehouseCodeList" placeholder="请选择或输入"
							:isJSON="true" keyName="locationCode" v-model="data.locationCode"></superwei-combox> -->
					</view>

				</view>
				<!-- 当前扫描信息 -->
				<view v-if="data.scanInfo" class="custom-form-card">
					<uni-collapse v-model="data.value">
						<uni-collapse-item titleBorder="none" :show-animation="true">
							<template v-slot:title>
								<view class="custom-card-title">
									<text class="title-line"></text>
									{{$t('distributedOut.atPresent')}}
								</view>
							</template>
							<view class="content">
								<view class="custom-card-itemOne">
									<text class="item-info-title">{{$t('distributedEnter.materialCoded')}}：</text>{{data.scanInfo.barcode}}
								</view>
								<!-- <view class="custom-card-itemOne">
									<text class="item-info-title">物料规格：</text>{{data.scanInfo.materialSpec}}
								</view> -->
								<view class="custom-card-itemOne" style="margin-top:5px;margin-bottom: 5px;">
									<view class="card-item-50">
										<text class="item-info-title">{{$t('distributedEnter.materialCode')}}：</text>{{data.scanInfo.materialCode}}
									</view>
									<view class="card-item-50">
										<text class="item-info-title">{{$t('distributedEnter.materialName')}}：</text>{{data.scanInfo.materialName}}
									</view>
								</view>
								<view class="custom-card-itemOne">
									<view class="card-item-50">
										<text class="item-info-title">{{$t('distributedEnter.qty')}}：</text>{{data.scanInfo.currentQty*1 + data.scanInfo.sendNum*1}}
									</view>
									<view class="card-item-50">
										<text class="item-info-title">{{$t('distributedEnter.uom')}}：</text>{{data.scanInfo.unit}}
									</view>
								</view>
							</view>
						</uni-collapse-item>
					</uni-collapse>
				</view>
				<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-margin-top">
					<view class="gui-title-line"></view>
					<text class="gui-primary-text gui-h6" style="padding-left:50rpx; padding-right:50rpx;">{{$t('stockManage.receiptMaterial')}}</text>
					<view class="gui-title-line"></view>
				</view>
				<uni-card class="element-auto gui-margin-top card-my">
					<view class="element-auto" style="height: 500rpx">
						<zb-table :columns="data.column" :stripe="true" :border="true" @customLook="customBtnFn" :cell-style="cellStyle" :cell-header-style="cellHeaderStyle"
							:data="data.wmsReceiptDs">
						</zb-table>
					</view>
				</uni-card>
				<!-- 底部操作栏 -->
				<view class="page-bottom-box bottom-postion">
					<view class="page-bottomBtn bottomBtn-bgcolor-green"  @click="handelCreatOrder">
						{{$t('stockManage.generate')}}
					</view>
				</view>
				<!-- 弹框填写数量 -->
				<uni-popup ref="inputDialog" type="center">
					<view v-if="data.scanInfo" class="input-dialog-box">
						<view class="input-dialog-content">
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialCode')}}:{{data.scanInfo.materialCode}}
							</view>
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialName')}}:{{data.scanInfo.materialName}}
							</view>
							<view class="input-dialog-item" v-if="data.scanInfo.materialSpec != ' '">
								{{$t('distributedEnter.materialSpec')}}:{{data.scanInfo.materialSpec || ''}}
							</view>
							<view class="input-dialog-item">
								{{$t('distributedEnter.uom')}}:{{data.scanInfo.unit}}
							</view>
							<view class="input-dialog-item">
								{{$t('materials.quantityInStorage')}}:{{data.scanInfo.showCurrentQty}}
							</view>
							<view class="gui-form-item" style="color: #dd524d">
								<text style="width: 200rpx;">{{$t('hardware.inventoryQuantity')}}：</text>
								<view>
									<input
									type="number"
									style="margin: 8rpx 0;"
									class="gui-form-input" 
									v-model="data.scanInfo.currentQty" 
									name="name1" 
									:placeholder="$t('pageTranslation.plsInputQtyOf')" />
								</view>
							</view>
							<!--  v-if="data.stockDetail.giftNum > 0"  -->
							<view v-if="data.scanInfo.sendNum != null" class="gui-form-item" style="color: #dd524d">
								<text>{{$t('stockManage.giveQty')}}：</text>
								<view>
									<input
									disabled
									style="margin: 8rpx 0;"
									class="gui-form-input"
									type="number"
									v-model="data.scanInfo.sendNum" 
									name="name1" 
									:placeholder="$t('translationImage.pleaseInput')" />
								</view>
							</view>
						</view>
						<view class="input-dialog-footer">
							<view class="input-dialog-button" @click="cancelFn">
								{{$t('calendar.cancel')}}
								</view>
							<view class="input-dialog-button dialog-button-left" @click="confirmFn">
								{{$t('calendar.confirm')}}
							</view>
						</view>
					</view>
				</uni-popup>

				<!-- 表格查看界面 -->
				<uni-popup ref="popup" type="center">
					<view class="input-dialog-box"
						style="padding: 40rpx 20rpx 20rpx 20rpx;border-radius: 22rpx;width: 600rpx;">
						<uni-icons class="popup-close-icons" type="closeempty" color="#9C9C9C" size="26"
							@click="closePopup"></uni-icons>
						<view class="custom-card-itemOne">
							<text class="item-info-title">{{$t('distributedEnter.materialCode')}}：</text>{{ data.wmsReceiptDsInfo.materialCode }}
						</view>
						<view class="custom-card-itemOne">
							<text class="item-info-title">{{$t('distributedEnter.materialName')}}：</text>{{ data.wmsReceiptDsInfo.materialName }}
						</view>
						<view class="custom-card-itemOne">
							<text class="item-info-title">{{$t('distributedEnter.materialSpec')}}：</text> {{ data.wmsReceiptDsInfo.materialSpec || ''}}
						</view>
						<view class="custom-card-itemOne">
							<text class="item-info-title">{{$t('hardware.receiptsQty')}}：</text>{{ data.wmsReceiptDsInfo.qty }}
						</view>
						<view class="custom-card-itemOne">
							<text class="item-info-title">{{$t('distributedEnter.uom')}}：</text>{{ data.wmsReceiptDsInfo.unit }}
						</view>
						<view class="custom-card-itemOne">
							<!-- {{$t('hardware.inventoryQuantity')}} -->
							<text class="item-info-title">{{$t('JsInternational.ofStock')}}：</text>{{ data.wmsReceiptDsInfo.instockQty }}
						</view>
						<view class="gui-form-item" style="color: #dd524d">
							<text>{{$t('stockManage.giveQty')}}：</text> {{ data.wmsReceiptDsInfo.sendNum }}
						</view>
					</view>
				</uni-popup>
			</scroll-view >
		</template>
	</gui-page>
</template>

<script setup>
	import { navigate, navigateBack } from '@/utils/routerSkip.js';
	import pdaScan from '@/hooks/pdaScan.js'
	import { getDataDictionaryFn, sortClass, pitchOnFn } from '@/utils/index.js'
	import {
		ref,
		toRaw,
		watch,
		computed,
		reactive,
		onMounted
	} from 'vue';
	import { useStore } from "vuex";
	import {
		findReceiptHById,
		wmsSelectWmsBarcodeInfo,
		wmsCommitReceipt,
	} from '@/api/api.js'
	import tableColor from '@/hooks/tableColor.js';
	import { basPdaOperationLogFn } from '@/utils/index.js';
    import { OPERATION_SCAN, OPERATION_LOOK,OPERATION_COMMIT} from '@/constant/index.js'
	import graceJS from "@/Grace6/js/grace.js";
	import { onBackPress } from '@dcloudio/uni-app';
	//JS国际化引入
	import { useI18n } from 'vue-i18n';
	const { t } = useI18n();

	let store = useStore();
	const { scan } = pdaScan()
	let { tableData } = tableColor();
	// 接受来自父组件的传参
	const props = defineProps({
		id: String,
	});
	const { cellStyle, cellHeaderStyle } = tableColor();
    let popup = ref(null)
	//页面弹框输入数量使用的变量
    let inputDialog = ref(null)
	let data = reactive({
		id: props.id,// 上级界面传过来的id
		value: ['0'],
		spScanList:[],//五金来料历史扫描数据
		scanValue:'',// 扫描的条码信息
		stockDetail:undefined,//查询信息
		wmsReceiptDs:[],//收料单信息
		wmsReceiptDsInfo:undefined,// 查看
		transferIntoList:[],// 仓库数组
		staticWarehouseCodeList:[],// 静态库位数组
		warehouseCodeList: [], // 目的库位
		warehouseName: '',// 选中库位名称
		warehouseCode:'',//选中库位的code
		locationCode: '',// 选中的库位名称
		scanInfo:undefined,//临时记录的扫描信息
		selectedOut: '',  //选中的仓库名称
		inputValue: '',
		scanNumber2:0,
		inventoryNum:0,//入库数量
		giveNum:null, //扫描弹框的赠送数量
		calculateData:[],//用于本地的计算data
		column: [{
			name: 'age',
			type: 'ailibtn',
			label: t('translationImage.operation'),
			scanValue: '',
			fixed: true,
			width: 80,
		},
		{
			name: 'materialCode',
			label: t('distributedEnter.materialCode'),
			width: 120,
			fixed: true,
			emptyString: '--'
		},
		{
			name: 'materialName',
			label: t('distributedEnter.materialName'),
		},
		{
			name: 'materialSpec',
			label:  t('distributedEnter.materialSpec'),
		},
		{
			name: 'unit',
			label:  t('distributedEnter.uom'),
		},
		{
			name: 'qty',
			label: t('hardware.receiptsQty')
		},
		{
			name: 'instockQty',
			label:t('hardware.inventoryQuantity')
		}, {
			name: 'sendNum',
			label: t('stockManage.giveQty')
		},
		{
			name: 'scanNum',
			// label: t('distributedEnter.scannedQuantity'),
			label: t('materials.normalReceivingQty')
		},
		],
		list: [],
	})
	onMounted(()=>{
		console.log('开始监听PDA扫码')
		uni.$on('scancodedate', (data) => {
			console.log('获取到的code：' + data.code)
			getCode(data.code, 'pda')
		})
		getRequestData()
	})
	//监听当前扫描信息的变化
	watch(() => data.scanInfo, (newVal) => {
		if(!newVal){
			data.warehouseName = ''
			data.locationCode = ''
			data.warehouseCode=''
		}else{
			data.warehouseName = newVal.warehouseName
			data.locationCode = newVal.locationCode
			data.warehouseCode=newVal.warehouseCode
		}
	}, {
		immediate: true,
		deep: true
	});
	// fqc扫描条码
	data.spScanList = computed(() => {
		return store.state.hardWare.spScanList
	})
	onBackPress((options) => {
		if (options.from == 'backbutton') {
			navBackCheck()
			return true;
		}
	})
	//导航栏左侧返回
	const clickLeftBack = () => {
		navBackCheck()
	}
	const navBackCheck = () => {
		if(!data.spScanList.length){
			uni.navigateBack({
				delta: 1
			});
			return  true
		}
		uni.showModal({
			title: t('smashRemoval.warmPrompt'),
			content: t('materials.unsubmittedDataIn'),
			success: function (res) {
				if (res.confirm) {
					store.dispatch('hardWare/resetSpSubmittedScanList',data.id)
					uni.navigateBack({
						delta: 1
					});
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});
	}
	// 计算方法
	const watcShowscanList = ()=>{
		//拿不到请求信息直接return
		if(!data.stockDetail || data.wmsReceiptDs.length == 0) return
		var newVal = data.spScanList
		let indexArr = newVal.filter(x => x.storeId == data.id)
		let filtNewVal = indexArr.length == 0 ? [] : indexArr[0].arr
		data.calculateData = filtNewVal
		// 当前无本地记录扫码数据 但有历史记录手动赋值本地扫码信息
		if(!data.scanInfo && filtNewVal.length>0){
			data.scanInfo = filtNewVal[0]
			data.warehouseName = data.scanInfo.warehouseName
			data.locationCode = data.scanInfo.locationCode
			data.warehouseCode=data.scanInfo.warehouseCode
			data.scanValue = data.scanInfo.barcode
		}
		// 当前有本地记录扫码数据 但无历史记录手动置空本地扫码信息
		if(data.scanInfo && filtNewVal.length==0){
			data.scanInfo = undefined
		}

		let sumCurrentQty = 0
		let sumSendNum = 0
		filtNewVal.forEach(item => {
			sumCurrentQty += Number(item.currentQty)
			//sumSendNum += Number(item.sendNum)
		});
	    // 遍历数组 查询当前扫描的物料信息 与当前的收集单信息相比对进行重新赋值
		data.wmsReceiptDs.forEach(element => {
			let scanNum =  0
			let sendNum =  0
			filtNewVal.forEach(item => {
				// 根据当前扫描的materialCode物料code  查询到相对应收集单信息
				if(element.materialCode == item.materialCode){
					scanNum = scanNum + Number(item.currentQty)
					//sendNum = sendNum + Number(item.sendNum)
				}
			});
			//element.sendNum = sendNum //赠送数量等同于物料数量
			element.scanNum = scanNum //物料数量
		});
		data.stockDetail.currentScanSumNum = sumCurrentQty + sumSendNum
		// data.stockDetail.giftNum = sumSendNum

		data.stockDetail.unPointNum = Number(data.stockDetail.sumQty) - Number(data.stockDetail.currentScanSumNum ) - Number(data.stockDetail.sumInstockQty) 
	
	}
	//监听 spScanList 变化
	watch(() => data.spScanList, (newVal) => {
		watcShowscanList()
	}, {
		immediate: true,
		deep: true
	});
	// 用户调起相机扫码
	const iconClick = async (type) => {
		console.log(type)
		if (type === 'suffix') {
			let code = await scan()
			getCode(code, 'scan')
		}
	}
	// 用户点击键盘上搜索
	const confirm = () => {
		getCode(data.scanValue, 'keydown')
	}
	// 获取code
	const getCode = (code, type) => {
		if(data.stockDetail.unPointNum == 0){
			uni.showToast({ title: t('JsInternational.qtyPending'), icon: "none" });
			return
		}
		let repetitionBool = false // 是否重复标识
		let tepList = toRaw(data.spScanList)
		tepList.forEach(x => {
			x.arr.forEach(k=>{
				if (code == k.barcode) {
					repetitionBool = true
					uni.showToast({ title: t('JsInternational.scanInputBarcode'), icon: "none" });
			        return
				}
			})
		});
		if(repetitionBool) return // 重复扫描 不执行以下流程
		data.scanValue = code
		let parmes = {
			barcode: code,
			selectType: 'incomingMaterial',
			receiptId: data.id,
			isSp:1,
		}
		wmsSelectWmsBarcodeInfo(parmes).then(res => {
			console.log(res)
			try {
				let inputParameter = JSON.stringify(parmes)
				let returnParameter = JSON.stringify(res)
				let operationPicture = '五金仓入库'
				let callInterface = res.rquestUrl
				let opertionParmes = {
					inputParameter,
					returnParameter,
					operationPicture,
					callInterface,
					responseCode:res.status,//返回状态
					errorMessage:res.message,//错误信息
					isPass:res.status == 200 ? 'Y' : 'N',//是否成功 Y N
					operationType:OPERATION_SCAN
				}
				basPdaOperationLogFn(opertionParmes)
			} catch (error) {
			}
			if (res.status == 200) {
				let bool = data.wmsReceiptDs.some((item) => {
					return item.materialCode == res.data.materialCode
				})
				if(!bool){
					uni.showToast({ title:t('materials.materialIsNot'), icon: "none" });
			        return
				}
				data.scanInfo = res.data
				data.scanInfo.sendNum = null //
				data.scanInfo.showCurrentQty = data.scanInfo.currentQty
				data.scanInfo.currentQty = ''
				// 筛选出和当前扫码一直的物料并提位
				if (data.wmsReceiptDs.length && data.wmsReceiptDs.length != 1) {
					for (var i = 0; i < data.wmsReceiptDs.length; i++) {
						var item = {}
						if (data.wmsReceiptDs[i].materialCode === res.data.materialCode) {
							item = data.wmsReceiptDs[i]
							data.wmsReceiptDs.splice(i, 1);
							data.wmsReceiptDs.unshift(item)
							data.scanInfo.sendNum = item.giftQty || null
							break;
						}
					}
				}
				inputDialog.value.open()
			} else {
				uni.showToast({ title: res.message, icon: "none" });
			}
		})
	}
	// 弹框的取消按钮
	const cancelFn = () => {
		data.scanInfo = undefined
		inputDialog.value.close();
	}
	//弹框的确定按钮
	const confirmFn = () => {
		let scanInfo = data.scanInfo
		// if(Number(scanInfo.currentQty) == 0){
		// 	uni.showToast({ title: t('JsInternational.scanSubmit'), icon: "none" });
		// }else{
			// t('JsInternational.scanSubmit')
			if(Number(scanInfo.currentQty) <= 0){
				uni.showToast({ title: t('materials.numberOfScans'), icon: "none" });
				return
			}

			if(Number(data.scanInfo.sendNum) > Number(data.stockDetail.giftNum)){
				uni.showToast({ title: t('pageTranslation.currentQtyOfGiveAway'), icon: "none" });
				return
			}
			// 计算待点数量  并且判断扫描数量是否超出收料单总数
			let wmsqty = 0
			let text = ''
			let sumSendm = 0 //当前扫码的总赠送数量
			// 计算当前物料剩余的扫描容量
		
			data.wmsReceiptDs.forEach((item)=>{
				sumSendm += Number(item.sendNum)
				if(item.materialCode == scanInfo.materialCode){
					wmsqty = Number(item.qty) - Number(item.scanNum)- Number(item.instockQty)
					text = item.materialName 
				}
			})
			// 拿到前物料中赠送数量 + 当前赠数量进行比对 超出提示
			// if(sumSendm + Number(data.scanInfo.sendNum) > Number(data.stockDetail.giftNum)){
			// 	uni.showToast({ title: t('pageTranslation.currentQtyOfGiveAway'), icon: "none" });
			// 	return
			// }
			// 判断当前物料是否超出单据总数
			// let min = wmsqty - Number(scanInfo.currentQty) - Number(scanInfo.sendNum)
			let min = wmsqty - Number(scanInfo.currentQty)
			if(min < 0){
				uni.showToast({ title: t('JsInternational.Scanning')+`${text}`+t('JsInternational.qtyGreaterThan'), icon: "none" });
				return
			}
			//判断当前物料数量 是否超出总收料单总数
			if(Number(scanInfo.currentQty)> data.stockDetail.sumQty){
				uni.showToast({ title: t('JsInternational.stockinQty'), icon: "none" });
				return
			}
			
			// 原扫描数量 + 当前扫描数量 = 当前已扫描总数量
			let sumCurrentNum = Number(data.stockDetail.currentScanSumNum) + Number(data.scanInfo.currentQty)
			// 待点 = 单据总数 - 当前已扫描总数量 - 已入库数量 - 赠送总数量
			let unPointNum = Number(data.stockDetail.sumQty) - sumCurrentNum - Number(data.stockDetail.sumInstockQty)
			if(unPointNum<0){
				uni.showToast({ title: t('JsInternational.stockinQty'), icon: "none" });
				return
			}
			data.scanInfo.storeId = data.id // 保存id 用户区分是那个收料单进来的数据
			store.dispatch('hardWare/setSpScanList', data.scanInfo)
			inputDialog.value.close();
		// }
	}
	const clickRight = () => {
		navigate({
			url:'/pages/hardware/hardwareEnterRecord'
		})
	}
	const closePopup = () =>{
		popup.value.close()	
	}
	// 查看
	const customBtnFn = (item, index) => {
		data.wmsReceiptDsInfo = item
		try {
			let inputParameter = JSON.stringify(item)
			let returnParameter = '无'
			let operationPicture = '五金仓入库'
			let callInterface = '无'
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode:'无',//返回状态
				errorMessage:'无',//错误信息
				isPass:'Y',//是否成功 Y N
				operationType:OPERATION_LOOK
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) {
		}
		popup.value.open()
	}
	// 查询初始化数据
	const getRequestData = () => {
		let parmes = {
			id: data.id
		}
		findReceiptHById(parmes).then(res => {
			try {
				let inputParameter = JSON.stringify(parmes)
				let returnParameter = JSON.stringify(res)
				let operationPicture = '五金仓入库'
				let callInterface = res.rquestUrl
				let opertionParmes = {
					inputParameter,
					returnParameter,
					operationPicture,
					callInterface,
					responseCode:res.status,//返回状态
					errorMessage:res.message,//错误信息
					isPass:res.status == 200 ? 'Y' : 'N',//是否成功 Y N
					operationType:OPERATION_LOOK
				}
				basPdaOperationLogFn(opertionParmes)
			} catch (error) {
			}
			if (res.status == 200) {
				
				let stockDetail = res.data;
				let unPointNum = Number(stockDetail.sumQty) - Number(stockDetail.sumInstockQty)
				stockDetail.currentScanSumNum = 0
				stockDetail.unPointNum = unPointNum 
				data.stockDetail = stockDetail
				// 获取展示收料单信息
				data.wmsReceiptDs = res.data.wmsReceiptDs
				
				 watcShowscanList()
			}
		})
	}
	// 生成退料单
	const handelCreatOrder = ()=> {
		if(data.calculateData.length == 0){
			uni.showToast({ title:t('stockManage.pleaseScanCode'), icon: "none" });
			return
		}
		// data.stockDetail.unPointNum != 0  原本条件，下面括号的位新改的条件
		if(data.stockDetail.unPointNum < 0){ 
			uni.showToast({ title: t('pageTranslation.plsScanOrInput'), icon: "none" });
			return
		}
		let sumSendm = 0
		data.wmsReceiptDs.forEach((item)=>{
			sumSendm += Number(item.sendNum)
		})
		if(sumSendm != (Number(data.stockDetail.giftNum)||0)){
			uni.showToast({ title: t('pageTranslation.plsScanOrInput'), icon: "none" });
			return
		}
		let tepData = toRaw(data.calculateData)
		let list = sortClass(tepData)
		let receiptBarcodes = []
		list.forEach(x => {
			let item = {
				materialCode:'',//物料code
				barcodeInfoVos:[], //条码信息
			}
			let dict = {
				qty:0,
				giftNum:0
			}
			x.forEach(k=>{
				console.log(k,'----dict-----')
				item.materialCode = k.materialCode
				dict.warehouseCode = k.warehouseCode
				dict.locationCode = k.locationCode
				dict.id = k.id
				dict.barcode = k.barcode//条码barcode
				data.wmsReceiptDs.forEach(m=>{
					if(m.materialCode== k.materialCode)
					{
						if(m.sendNum>0)
						{
							dict.qty += Number(k.currentQty)//用户输入的qty
							dict.giftNum += Number(k.currentQty) //赠送数量
						}
						else{
						dict.qty += Number(k.currentQty)//用户输入的qty
						dict.giftNum += 0 //赠送数量
						}
					}
				})
				
				
			})
			item.barcodeInfoVos.push(dict)
			receiptBarcodes.push(item)
		});
		let parmes = {
			isSp:1,
			id: data.id, // 收料单id
			receiptCode: data.stockDetail.receiptCode, //收料单code
			receiptBarcodes: receiptBarcodes // 条码信息
		}
		// console.log(JSON.stringify(parmes),'----parmes----')
		// return
		// 添加加载框
		uni.showLoading({
			title: 'loading',
			mask: true
		});
		wmsCommitReceipt(parmes).then(res => {
			console.log(res)
			try {
				let inputParameter = JSON.stringify(parmes)
				let returnParameter = JSON.stringify(res)
				let operationPicture = '五金仓入库'
				let callInterface = res.rquestUrl
				let opertionParmes = {
					inputParameter,
					returnParameter,
					operationPicture,
					callInterface,
					responseCode:res.status,//返回状态
					errorMessage:res.message,//错误信息
					isPass:res.status == 200 ? 'Y' : 'N',//是否成功 Y N
					operationType:OPERATION_COMMIT
				}
				basPdaOperationLogFn(opertionParmes)
			} catch (error) {
			}
			if (res.status == 200) {
				//隐藏加载框
				uni.hideLoading();
				//删除已提交的数据
				data.scanValue = ''
				uni.showToast({ title: t('smashRemoval.submitSuccessfully'), icon: "none" });
				store.dispatch('hardWare/resetSpSubmittedScanList',data.id)
				// navigateBack()
				// 提交成功重新刷线当前界面
				getRequestData()
				// 返还上一个页面
				uni.navigateBack({
					delta: 1
				});
			} else {
				uni.showToast({ title: res.message, icon: "none" });
			}
		})
	}
</script>

<style lang="scss" scoped>
.card-mini-body{
	margin-top: 10rpx !important;
	.mini-item-title{
		font-size: 25rpx;
	}
}

.noborder{
	border: none !important;
	margin-bottom: 20rpx;
}
.maxWidth{
	width: 100% !important; 
}
// .card-my{
// 	display: flex;
// 	flex-direction: column;
// }
</style>
